<template>
	<view>
		<view class="nav2">
			<u-navbar title="确认订单" bgColor="transparent" :fixed="false" autoBack>
			</u-navbar>
		</view>
		<view class="ml30 mr30">
			<view class="bgFff radius30 p30">
				<view class="flex-jus" @click="openUrl('/subpage/me/addressList?type=order')">
					<view class="flex flex-start" v-if="address.id">
						<image src="../../static/images/order/icon1.png" mode="" style="width: 36rpx;height: 36rpx;">
						</image>
						<view class="ml10 flex1">
							<view class="f26 c343">{{address.userAddr}} - {{address.houseNumber}}</view>
							<view class="f24 c666 mt10">{{address.realName}} {{address.phone}}</view>
						</view>
					</view>
					<view class="flex" v-else>
						<image src="../../static/images/order/icon1.png" mode="" style="width: 36rpx;height: 36rpx;">
						</image>
						<text class="c343 f26 ml10">选择地址</text>
					</view>
					<view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<u-line color="#ddd" margin="30rpx 0"></u-line>
				<view class="flex-jus" v-if="detail.isMulti == 1" @click="show_serve = true">
					<view class="flex">
						<image src="../../static/images/order/icon2.png" mode="" style="width: 36rpx;height: 36rpx;">
						</image>
						<text class="c343 f26 ml10">选择服务</text>
					</view>
					<view class="flex">
						<text class="c343 f26 mr10">{{selSku.proName}}</text>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="flex-jus" v-if="detail.isMulti == 2" @click="show_serve = true">
					<view class="flex">
						<image src="../../static/images/order/icon2.png" mode="" style="width: 36rpx;height: 36rpx;">
						</image>
						<text class="c343 f26 ml10">选择服务</text>
					</view>
					<view class="flex">
						<view class="">
							<view class="c343 f26 mr10 flex-jus" v-for="(item,index) in selSku2" :key="item.id">
								<text>{{item.proName}}</text>
								<text>X{{item.buyCount}}</text>
							</view>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<u-line color="#ddd" margin="30rpx 0"></u-line>
				<view class="flex-jus" @click="show_time = true">
					<view class="flex">
						<image src="../../static/images/order/icon3.png" mode="" style="width: 36rpx;height: 36rpx;">
						</image>
						<text class="c343 f26 ml10">期望上门时间</text>
					</view>
					<view class="flex">
						<text class="c343 f26 mr10">{{serve_time}}</text>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<u-line color="#ddd" margin="30rpx 0"></u-line>
				<view class="flex-jus" @click="couponList.length > 0?show_yhq = true:''">
					<view class="flex">
						<image src="../../static/images/order/icon4.png" mode="" style="width: 36rpx;height: 36rpx;">
						</image>
						<text class="c343 f26 ml10">优惠</text>
					</view>
					<view class="flex" v-if="couponList.length > 0">
						<text
							class="c343 f26 mr10">{{sel_Coupon.id?(sel_Coupon.coupTitle + '-' + coupon_amount + '元'):'有待使用优惠券'}}</text>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="flex" v-else>
						<text class="c343 f26 mr10">暂无可使用优惠券</text>
					</view>
				</view>
				<u-line color="#ddd" margin="30rpx 0 0 0"></u-line>
			</view>
			<u-gap height="10"></u-gap>
			<view class="bgFff radius30 p30" @click="show_remark = true">
				<view class="flex-jus">
					<view class="flex flex1">
						<text class="c343 f26">备注</text>
					</view>
					<view class="flex flex1 textR">
						<text class="c343 f26 mr10 ml10 textoverflow2 flex1">{{remark}}</text>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<u-line color="#ddd" margin="30rpx 0"></u-line>
				<view class="flex-jus">
					<view class="flex">
						<text class="c343 f26">支付方式</text>
					</view>
					<view class="flex">
						<text class="c343 f26 mr10">微信支付</text>
						<image src="../../static/images/order/wx.png" mode="" style="width: 40rpx;height: 40rpx;">
						</image>
					</view>
				</view>
				<u-line color="#ddd" margin="30rpx 0 0 0"></u-line>
			</view>
			<u-gap height="10"></u-gap>
			<view class="bgFff radius30 p30">
				<view class="flex-jus">
					<view class="flex">
						<text class="c343 f26 bold">购买须知</text>
					</view>
					<view>
						<u-button color="#fff4ec" :customStyle="{'color':'#FF7F1C','height':'50rpx','fontSize':'24rpx'}"
							shape="circle" @click="show_buynote = true">查看购买须知</u-button>
					</view>
				</view>
				<u-gap height="10"></u-gap>
				<view class="c666 f26 textoverflow2">
					<u-parse :content="buyNotice.protText"></u-parse>
				</view>
				<u-gap height="10"></u-gap>
				<!-- <view class="flex">
					<u-checkbox-group v-model="checked">
						<u-checkbox shape="circle" size="14" activeColor="#FFDE6D" labelSize="12" label="我已阅读并同意"
							:name="true">
						</u-checkbox>
					</u-checkbox-group>
					<text class="f24 blue" @click="nologinJump('/subpage/news/detail?code=5')">《“东楚畅通”服务协议》</text>
				</view> -->
			</view>
			<u-gap height="20"></u-gap>
			<view class="textC" @click="maketel(config.phone)">
				<image src="../static/housekeeping/kf.png" mode="widthFix" style="width: 30%;"></image>
			</view>
		</view>
		<u-gap height="100"></u-gap>
		<view class="fix-bot">
			<view class="fix-bot-box ml30 mr30 bgFff p20 radius30 flex-jus">
				<view class="cyellow">
					<text class="f24">￥</text>
					<text class="f40 bold" v-if="sel_Coupon.id">{{total_amount}}</text>
					<text class="f40 bold" v-else>{{detail.isMulti == 1?selSku.proPrice:amount}}</text>
				</view>
				<view>
					<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'80rpx'}" shape="circle"
						throttleTime="3000" @click="subscription">预约并支付</u-button>
				</view>
			</view>
		</view>
		<!-- //选择服务 -->
		<u-popup :show="show_serve" @close="show_serve = false" @open="show_serve = true" closeable round="20">
			<view class="p30">
				<view class="flex flex-start">
					<u-image :src="api_host + detail.icon" mode="" width="98px" height="98px" radius="10"></u-image>
					<view class="ml10 p10">
						<view class="c343">{{detail.title}}</view>
						<u-gap height="5"></u-gap>
						<view class="c999 f24" v-if="detail.isMulti == 1">已选：{{waitSku.proName}}</view>
						<view class="c999 f24" v-else>已选：
							<text v-for="(item,index) in waitSku2"
								:key="index">{{item.proName}}X{{item.buyCount}}/</text>
						</view>
						<u-gap height="20"></u-gap>
						<view class="cyellow" v-if="detail.isMulti == 1">
							<text class="f24">￥</text>
							<text class="f32">{{waitSku.proPrice}}</text>
						</view>
						<view class="cyellow" v-else>
							<text class="f24">￥</text>
							<text class="f32">{{waitSku2price}}</text>
						</view>
					</view>
				</view>
				<u-gap height="10"></u-gap>
				<view v-if="detail.isMulti == 1">
					<view class="bgF7 p30 radiusBox ser_item flex-jus f26 mb30"
						:class="waitSku.id == item.id?'active':''" v-for="(item,index) in skuList" :key="item.id"
						@click="selBtn(item,'sku')">
						<text class="c343">{{item.proName}}</text>
						<view class="c343">
							<text class="f24">￥</text>
							<text class="f28">{{item.proPrice}}</text>
						</view>
					</view>
					<u-gap height="20"></u-gap>
					<view>
						<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'90rpx'}" shape="circle"
							@click="selBtn('','sureSku')">确认选择</u-button>
					</view>
				</view>
				<view v-if="detail.isMulti == 2">
					<view class="bgF7 p30 radiusBox ser_item flex-jus f26 mb30" v-for="(item,index) in skuList"
						:key="item.id">
						<view class="flex">
							<text class="c343">{{item.proName}}</text>
							<view class="c343 ml10">
								<text class="f24">￥</text>
								<text class="f28">{{item.proPrice}}</text>
							</view>
						</view>
						<view>
							<u-number-box bgColor="#fff" :min="0" v-model="item.buyCount" disabledInput
								@change="(val) =>{skuNumberchange(val,item)}"></u-number-box>
						</view>
					</view>
					<view class="mt20">
						<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'100rpx'}" shape="circle"
							@click="selBtn('','sku2')">确认选择</u-button>
					</view>
				</view>
				<u-gap height="10"></u-gap>
			</view>
		</u-popup>
		<!-- //上门时间 -->
		<u-popup :show="show_time" @close="show_time = false" @open="show_time = true" closeable round="20">
			<view class="p30">
				<view class="f28 c343 bold">请选择期望上门时间</view>
				<u-gap height="20"></u-gap>
				<view class="flex-jus flex-start">
					<view class="bgF7 textC mr30 p20 radiusBox" style="width: 30%;">
						<view class="p20 radiusBox mb20 f24" :class="{'day_active':dayIndex == index}"
							v-for="(item,index) in days" :key="index" @click="timeIndex = -1,dayIndex = index">
							<view class="c343">{{item.daytext}}</view>
							<view class="c999">{{item.date}}</view>
						</view>
					</view>
					<view class="flex1 ml30">
						<view class="flex1 textC p20 f26"
							:class="{'c999':today == days[dayIndex].day && todayHour >= item.time,'time_active':timeIndex == index}"
							v-for="(item,index) in times" :key="index"
							@click="today == days[dayIndex].day && todayHour >= item.time?'':timeIndex = index">
							<view class="flex-jus">
								<text class="f26">{{item.text}}</text>
								<u-icon v-if="timeIndex == index" size="18" name="checkmark-circle-fill"
									color="#FFDE6D"></u-icon>
							</view>
						</view>
					</view>
				</view>
				<u-gap height="10"></u-gap>
				<view>
					<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'90rpx'}" shape="circle"
						@click="selBtn('','time')">确认选择</u-button>
				</view>
			</view>
		</u-popup>
		<!-- //优惠券 -->
		<u-popup :show="show_yhq" @close="show_yhq = false" @open="show_yhq = true" closeable round="20">
			<view class="p30">
				<view class="f28 c343 bold">优惠</view>
				<view class="f24 c999">可使用优惠券</view>
				<u-gap height="20"></u-gap>
				<view class="pop-scroll-box">
					<view class="yhq-item pore p30 mb20" v-for="(item,index) in couponList" :key="item.id"
						@click="chooseCoupon(index)">
						<view class="flex" v-if="item.conpType == 1">
							<view class="mr30 textC">
								<view class="cyellow">
									<text class="f24">￥</text>
									<text class="f40 bold">{{item.conpTextObject.deductionAmount}}</text>
								</view>
								<view class="cyellow f24">满{{item.conpTextObject.fullAmount}}可用</view>
							</view>
							<u-line length="100rpx" color="#eee" direction="col"></u-line>
							<view class="ml30">
								<view class="c343 bold f28 mb10">{{item.name}}</view>
								<view class="f24" v-if="item.lifespanType == 1">有效期：{{item.lifespanTextObject.startTime}} ~
									{{item.lifespanTextObject.endTime}}
								</view>
								<view class="f24" v-if="item.lifespanType == 2">
									有效期：{{item.lifespanTextObject.lifespan}}天</view>
							</view>
						</view>
						<view class="flex" v-if="item.conpType == 2">
							<view class="mr30">
								<view class="cyellow textC">
									<!-- <text class="f24">￥</text> -->
									<text class="f40 bold">{{item.conpTextObject.discount/10}}折</text>
								</view>
								<view class="cyellow f24">最高减{{item.conpTextObject.maxReduction}}元</view>
							</view>
							<u-line length="100rpx" color="#eee" direction="col"></u-line>
							<view class="ml30">
								<view class="c343 bold f28 mb10">{{item.name}}</view>
								<view class="f24" v-if="item.lifespanType == 1">有效期：{{item.lifespanTextObject.startTime}} ~
									{{item.lifespanTextObject.endTime}}
								</view>
								<view class="f24" v-if="item.lifespanType == 2">
									有效期：{{item.lifespanTextObject.lifespan}}天</view>
							</view>
						</view>
						<view class="flex" v-if="item.conpType == 3">	
							<view class="mr30">
								<view class="cyellow">
									<text class="f32 bold">无门槛</text>
								</view>
								<view class="f24" :class="item.useStauts > 0?'c999':'cyellow'">
									满0可用</view>
							</view>
							<u-line length="100rpx" color="#eee" direction="col"></u-line>
							<view class="ml30">
								<view class="c343 bold f28 mb10">{{item.name}}</view>
								<view class="f24" v-if="item.lifespanType == 1">有效期：{{item.lifespanTextObject.startTime}} ~
									{{item.lifespanTextObject.endTime}}
								</view>
								<view class="f24" v-if="item.lifespanType == 2">
									有效期：{{item.lifespanTextObject.lifespan}}天</view>
							</view>
						</view>
						<u-gap height="30"></u-gap>
						<view class="f24 c343">
							{{item.range == 1?'全家政业务':'指定家政业务'}}
						</view>
						<image src="../../static/images/order/yhq.png" mode="" class="yhq_bg"></image>
						<view class="yhq_check" v-show="couponIndex == index">
							<u-icon size="20" name="checkmark-circle-fill" color="#FFDE6D"></u-icon>
						</view>
					</view>
				</view>
				<u-gap height="10"></u-gap>
				<view>
					<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'90rpx'}" shape="circle"
						@click="selBtn('','coupon')">确认选择</u-button>
				</view>
			</view>
		</u-popup>
		<!-- //订单备注 -->
		<u-popup :show="show_remark" @close="show_remark = false" @open="show_remark = true" closeable round="20">
			<view class="p30">
				<view class="f28 c343 bold">订单备注</view>
				<u-gap height="20"></u-gap>
				<view class="flex flex-wrap">
					<view class="m10" v-for="(item,index) in remarkList" :key="index">
						<u-button color="#f7f7f7" :customStyle="{'color':'#34314F','height':'60rpx','fontSize':'24rpx'}"
							shape="circle" @click="chooseRemark(item)">{{item.dictLabel}}</u-button>
					</view>
				</view>
				<u-gap height="20"></u-gap>
				<view>
					<u--textarea v-model="remark1" placeholder="请输入其他备注事项" height="200rpx"
						border="surround"></u--textarea>
				</view>
				<u-gap height="20"></u-gap>
				<view>
					<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'90rpx'}" shape="circle"
						@click="selBtn('','remark')">确认选择</u-button>
				</view>
			</view>
		</u-popup>
		<!-- //购买须知 -->
		<u-popup :show="show_buynote" @close="show_buynote = false" @open="show_buynote = true" closeable round="20">
			<view class="p30">
				<view class="f28 c343 bold">{{buyNotice.protName}}</view>
				<u-gap height="20"></u-gap>
				<view class="f26">
					<u-parse :content="buyNotice.protText"></u-parse>
				</view>
				<u-gap height="20"></u-gap>
				<view>
					<u-button color="#21B9AD" :customStyle="{'color':'#fff','height':'80rpx'}" shape="circle"
						@click="show_buynote = false">我已知晓</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import appInfo from '@/common/appInfo.js'
	import {
		getProtocolBycode,
		getdefAddr,
		getCanuseCoupon,
		getDictdata
	} from '@/common/api_user.js'
	import {
		getHomedetail
	} from '@/common/api_housekeeping.js'
	import {
		createOrder,
		payOrder,
		getOrderamount
	} from '@/common/api_order.js'
	let now = new Date()
	let today = now.getDay()
	let todayHour = now.getHours()
	export default {
		name: '',
		data() {
			return {
				notice: '亲爱的用户，感谢您选择东楚畅通服务。我们注意到您填写的地址目前尚未覆盖在我们的服务区域内。为了提供更优质的服务体验，我们目前仅在黄石市的黄石港区、下陆区和西塞山区提供服务。请您放心，我们正积极扩展服务范围，未来将有更多区域加入我们的服务版图。请您持续关注我们的更新，期待不久的将来能为您提供服务。再次感谢您的理解与支持！',
				id: '',
				detail: {},
				address: {},
				skuList: [],
				total_amount: '0.00',
				coupon_amount: '0.00',
				selSku: {},
				waitSku: {},
				selSku2: [],
				waitSku2: [],
				waitSku2price: '0.00',
				couponList: [],
				show_serve: false,
				show_serve2: false,
				serve_time: "",
				show_time: false,
				couponIndex: 0,
				show_yhq: false,
				sel_Coupon: {},
				show_remark: false,
				show_buynote: false,
				buyNotice: {},
				checked: [],
				remark: '',
				remark1: '',
				days: [],
				dayIndex: 0,
				timeIndex: -1,
				today,
				todayHour,
				remarkList: [],
				times: [{
						text: '08:00 - 09:00',
						time: 7
					},
					{
						text: '09:00 - 10:00',
						time: 8
					},
					{
						text: '10:00 - 11:00',
						time: 9
					},
					{
						text: '11:00 - 12:00',
						time: 10
					},
					{
						text: '12:00 - 13:00',
						time: 11
					},
					{
						text: '13:00 - 14:00',
						time: 12
					},
					{
						text: '14:00 - 15:00',
						time: 13
					},
					{
						text: '15:00 - 16:00',
						time: 14
					},
					{
						text: '16:00 - 17:00',
						time: 15
					},
					{
						text: '17:00 - 18:00',
						time: 16
					},
					{
						text: '18:00 - 19:00',
						time: 17
					},
					{
						text: '19:00 - 20:00',
						time: 18
					},
					{
						text: '20:00 - 21:00',
						time: 19
					}
				]
			}
		},
		onLoad(option) {
			this.id = option.id
			this.selSku.id = option.sku_id
			this.getDictdata()
			this.getHomedetail()
			this.getBuyNotice()
			this.getDays()
		},
		onShow() {
			this.getdefAddr()
		},
		computed: {
			amount() {
				let amount = 0
				this.selSku2.forEach(function(val, idx, arr) {
					amount += val.buyCount * val.proPrice;
				}, 0);
				return amount
			}
		},
		watch: {
			amount() {
				if (this.sel_Coupon.id) {
					this.getOrderamount()
				}
			}
		},
		methods: {
			async getDictdata() { //下单备注
				const res = await getDictdata({
					dictType: 'sys_order_remark'
				})
				if (res.code == 200) {
					this.remarkList = res.data
				}
			},
			async getBuyNotice() { //购买须知
				uni.showLoading({
					mask: true
				})
				const res = await getProtocolBycode({
					code: '6'
				})
				if (res.code == 200) {
					this.buyNotice = res.data
				}
				uni.hideLoading()
			},
			async getOrderamount() { //计算总价
				uni.showLoading({
					mask: true
				})
				const res = await getOrderamount({
					id: this.sel_Coupon.id || '',
					price: this.detail.isMulti == 1 ? Number(this.selSku.proPrice).toFixed(2) : Number(this
						.amount).toFixed(2)
				})
				if (res.code == 200) {
					this.total_amount = res.data.orderPrice
					this.coupon_amount = res.data.discountPrice
				}
				uni.hideLoading()
			},
			async getdefAddr() { //获取用户默认地址
				uni.showLoading({
					mask: true
				})
				const res = await getdefAddr()
				if (res.code == 200) {
					let data = res.data
					if (data && data.id) {
						// if (data.userAddr.indexOf('黄石港区') != -1 || data.userAddr.indexOf('下陆区') != -1 || data.userAddr
						// 	.indexOf('西塞山区') != -1) {
						// 	this.address = res.data
						// } else {
						// 	this.address = {}
						// 	uni.showModal({
						// 		title: '提示',
						// 		content: this.notice,
						// 		showCancel: false
						// 	})
						// }
						this.address = res.data
					} else {
						this.address = {}
					}
				}
				uni.hideLoading()
			},
			async getCanuseCoupon() { //获取可用优惠券
				uni.showLoading({
					mask: true
				})
				const res = await getCanuseCoupon({
					type: 1,
					proId: this.id,
					price: this.detail.isMulti == 1 ? this.selSku.proPrice : this.amount
				})
				if (res.code == 200) {
					this.couponList = res.data || []
					console.log(this.couponList);
					if (this.couponList.length > 0) {
						this.sel_Coupon = this.couponList[0]
						this.getOrderamount()
					}
				}
				uni.hideLoading()
			},
			getDays() {
				let weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
				let neardays = ['今天', '明天', '后天']
				let nowTimes = now.getTime()
				let oneDaytimes = 24 * 60 * 60 * 1000 //一天的毫秒
				for (var i = 0; i < 7; i++) {
					let times = nowTimes + i * oneDaytimes
					let itemDay = this.$utils.getWeek(times)
					let daynear = itemDay - this.today
					this.days.push({
						daytext: (daynear >= 0 && daynear <= 2) ? neardays[daynear] : weeks[this.$utils.getWeek(
							times)],
						day: itemDay,
						date: this.$u.timeFormat(nowTimes + i * oneDaytimes, 'mm月dd日')
					})
				}
			},
			async getHomedetail() {
				uni.showLoading({
					mask: true
				})
				const res = await getHomedetail({
					id: this.id
				})
				if (res.code == 200) {
					this.detail = res.data
					const {
						images,
						detailList
					} = this.detail
					if (this.detail.isMulti == 1) {
						this.skuList = detailList
						this.selSku = this.skuList.find(item => item.id == this.selSku.id)
						this.waitSku = this.selSku
						this.selSku.total_amount = '0.00'
					} else {
						let data = uni.getStorageSync('proSku');
						this.skuList = JSON.parse(JSON.stringify(data));
						this.selSku2 = data.filter(item => item.buyCount > 0)
						this.waitSku2 = this.selSku2
						this.getTotalprice()
					}
					this.getCanuseCoupon()
				}
				uni.hideLoading()
			},
			getTotalprice() {
				const that = this
				console.log(this.waitSku2);
				let sum = 0;
				for (let i = 0; i < this.waitSku2.length; i++) {
					sum += this.waitSku2[i].proPrice * this.waitSku2[i].buyCount;
				}
				that.waitSku2price = sum;
			},
			skuNumberchange(val, item) {
				item.buyCount = val.value
				this.waitSku2 = this.skuList.filter(item => item.buyCount > 0)
				this.getTotalprice()
			},
			chooseCoupon(index) {
				if (this.couponIndex == index) {
					this.couponIndex = -1
					return false
				}
				this.couponIndex = index
			},
			chooseRemark(item) {
				this.remark1 = this.remark1 + item.dictLabel
			},
			selBtn(item, type) {
				switch (type) {
					case 'sku':
						this.waitSku = item
						//this.show_serve = false
						break;
					case 'sureSku':
						this.selSku = this.waitSku
						this.show_serve = false
						this.getCanuseCoupon()
						break;
					case 'time':
						if (this.timeIndex < 0) {
							uni.showToast({
								title: '请选择时间段',
								icon: 'none'
							})
							return false
						}
						this.serve_time = this.days[this.dayIndex].date + ' ' + this.times[this.timeIndex].text
						this.show_time = false
						break;
					case 'remark':
						if (!this.remark1) {
							uni.showToast({
								title: '请填写备注',
								icon: 'none'
							})
							return false
						}
						this.remark = this.remark1
						this.show_remark = false
						break;
					case 'sku2':
						let data = JSON.parse(JSON.stringify(this.skuList));
						let hasSku = data.some(item => item.buyCount > 0)
						if (!hasSku) {
							uni.showToast({
								title: '请选择服务类型',
								icon: 'none'
							})
							return false
						}
						this.selSku2 = data.filter(item => item.buyCount > 0)
						this.show_serve = false
						this.getCanuseCoupon()
						break;
					case 'coupon':
						if (this.couponIndex == -1) {
							this.sel_Coupon = {}
						} else {
							this.sel_Coupon = this.couponList[this.couponIndex]
						}
						this.getOrderamount()
						this.show_yhq = false
						break;
				}
			},
			async subscription() {
				const that = this
				if (!this.address.id) {
					uni.showToast({
						title: '请选择地址',
						icon: 'none'
					})
					return false
				}
				if (!this.serve_time) {
					uni.showToast({
						title: '请选择上门时间',
						icon: 'none'
					})
					return false
				}
				// if (!this.checked[0]) {
				// 	uni.showToast({
				// 		title: '我请阅读并同意《“东楚畅通”服务协议》',
				// 		icon: 'none'
				// 	})
				// 	return false
				// }
				// #ifdef MP-WEIXIN
				let messageRes = await this.$utils.messageSubscriptionAuthorization(appInfo.tmplIds.order);
				console.log(9999, messageRes);
				// if (messageRes.isTip) {
				// 	uni.showToast({
				// 		title: messageRes.msg,
				// 		icon: 'none'
				// 	});
				// }
				// #endif
				that.pay()
			},
			async pay() {
				let orderDetails = []
				if (this.detail.isMulti == 1) {
					orderDetails = [{
						wareId: this.selSku.id,
						buyCount: 1,
						price: this.selSku.proPrice
					}]
				} else {
					this.selSku2.forEach(item => {
						orderDetails.push({
							wareId: item.id,
							buyCount: item.buyCount,
							price: item.proPrice
						})
					})
				}
				let data = {
					proId: this.id,
					addrId: this.address.id,
					timePeriod: this.serve_time,
					coupId: this.sel_Coupon.id || '',
					orderType: '1',
					orderDetails,
					remark: this.remark
				}
				uni.showLoading({
					mask: true
				})
				
				const res = await createOrder(data)
				if (res.code == 200) {
					this.payOrder(res.data.id)
				} else {
					uni.showToast({
						icon: 'none',
						duration: 3000,
						title: res.data.msg
					});
				}
				uni.hideLoading()
			},
			async payOrder(order_id) {
				uni.showLoading({
					mask: true,
					title: '正在支付中...'
				})
				const res = await payOrder({
					id: order_id
				})
				if (res.code == 200) {
					let config = res.data
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: config.timeStamp.toString(),
						nonceStr: config.nonceStr,
						package: 'prepay_id=' + config.package.prepay_id,
						signType: config.signType,
						paySign: config.paySign,
						success() {
							uni.hideLoading()
							uni.showToast({
								title: '支付成功',
								icon: 'success',
								success() {
									uni.redirectTo({
										url: '/subpage/order/detail?id=' + order_id
									})
								}
							})
						},
						fail(err) {
							console.log(222, err);
							uni.hideLoading()
							uni.showToast({
								title: '支付取消',
								icon: 'error'
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/subpage/order/detail?id=' + order_id
								})
							}, 500)
						}
					})
				}
				uni.hideLoading()

			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FEF4E8;
	}

	.disabled {
		color: #ddd;
	}

	.day_active {
		background-color: #fff;

		* {
			color: #FF7F1C;
		}
	}

	.time_active {
		color: #FF7F1C;
	}

	.fix-bot {
		bottom: 20rpx;
	}

	.ser_item {
		border: 1px solid transparent;
	}

	.active {
		border-color: #FF7F1C;
		background-color: #FFF6EF;

		* {
			color: #FF7F1C;
		}
	}

	.pop-scroll-box {
		height: 700rpx;
		overflow-y: scroll;
	}

	.yhq_bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}

	.yhq_check {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
	}
</style>